package com.lyj.cloud.entity;

import javax.persistence.*;

import java.util.Set;

@Entity
@Table(name="t_role")
public class Role extends BaseIdentity {
	
  	private static final long serialVersionUID = 1L;
	private String code;
  	private String name;
	@Transient
	private String description;
  
  	@OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL,mappedBy="role")
  	private Set<UsersRoles> usersRoles ;
  /*
  @ManyToMany(fetch=FetchType.LAZY)
  @Cascade(value=org.hibernate.annotations.CascadeType.SAVE_UPDATE)
  @JoinTable(name="t_role_resource",
  		joinColumns={@JoinColumn(name="roleId")},
  		inverseJoinColumns={@JoinColumn(name="resourceId")}
  )
  @OrderBy("creationTime desc")
  private Set<Resource> roleResources = new HashSet<Resource>(0);
  */

//  @IsCode
  private Integer type;

  public Role()
  {
  }

  public Role(String roleName)
  {
    this.name = roleName;
  }

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public Set<UsersRoles> getUsersRoles() {
		return usersRoles;
	}
	
	public void setUsersRoles(Set<UsersRoles> usersRoles) {
		this.usersRoles = usersRoles;
	}
	
	public Integer getType() {
		return type;
	}
	
	public void setType(Integer type) {
		this.type = type;
	}

	@Override
	public String getDescription() {
		return description;
	}

	@Override
	public void setDescription(String description) {
		this.description = description;
	}

	@Override
	public String toString() {
		return "Role [roleName=" + name + ", type=" + type + "]";
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((code == null) ? 0 : code.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Role other = (Role) obj;
		if (code == null) {
			if (other.code != null)
				return false;
		} else if (!code.equals(other.code))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		return true;
	}

}